#!/bin/sh

BUNDLE_IDENTIFIER=com.bombich.ccc
dest="$3"
log="/Library/Logs/CCC.log"

echo "chowning $BUNDLE_IDENTIFIER.plist" >> $log 2>&1
chown root:wheel "$dest"/Library/LaunchDaemons/$BUNDLE_IDENTIFIER.plist >> $log 2>&1
chmod 644 "$dest"/Library/LaunchDaemons/$BUNDLE_IDENTIFIER.plist >> $log 2>&1

echo "chowning /Library/PrivilegedHelperTools/$BUNDLE_IDENTIFIER" >> $log 2>&1
chown root:wheel "$dest"/Library/PrivilegedHelperTools/$BUNDLE_IDENTIFIER >> $log 2>&1
chmod 755 "$dest"/Library/PrivilegedHelperTools/$BUNDLE_IDENTIFIER >> $log 2>&1

if [ "$dest" = "/" ]; then
	echo "Loading LaunchDaemon" >> $log 2>&1
	launchctl load /Library/LaunchDaemons/$BUNDLE_IDENTIFIER.plist >> $log 2>&1
fi
